<template>
  <div class="rank-container">
    <gltitle :titleSize="titleSize" :is_mt="is_mt" v-if="!$store.state.isApp"></gltitle>

    <div class="container">
      <div class="rank-top-box">
          <div class="box1">
              <div class="img-bg img1">
                <img  class="rank" src="@/assets/images/icon-rank1.png" alt="">
                <img class="head" :src="rank3Data.item2.avatar?rank3Data.item2.avatar:require('@/assets/images/photo3.png')" alt="">
              </div>
              <div>{{rank3Data.item2.nickname}}</div>
              <div>${{rank3Data.item2.profit}}</div>
          </div>
          <div class="box2">
            <div class="img-bg img2">
              <img  class="rank" src="@/assets/images/icon-rank2.png" alt="">
              <img  class="head" :src="rank3Data.item1.avatar?rank3Data.item1.avatar:require('@/assets/images/photo3.png')" alt="">
            </div>
            <div>{{rank3Data.item1.nickname}}</div>
            <div>${{rank3Data.item1.profit}}</div>
          </div>
          <div class="box3">
            <div class="img-bg img3">
              <img  class="rank" src="@/assets/images/icon-rank3.png" alt="">
              <img class="head" :src="rank3Data.item3.avatar?rank3Data.item3.avatar:require('@/assets/images/photo3.png')" alt="">
            </div>
            <div>{{rank3Data.item3.nickname}}</div>
            <div>${{rank3Data.item3.profit}}</div>
          </div>
      </div>

      <div class="record-con">
        <van-list v-model="loading" :finished="finished" :loading-text="$t('load.loading')" @load="onLoad">
          <van-cell v-for="(item, index) in list" :key="index">
             <div class="item-box">
                <div class="info">
                  <img class="head" :src="item.avatar?item.avatar:require('@/assets/images/photo3.png')" alt="">
                   <div class="profit-box">
                      <div class="name">{{item.nickname}}</div>
                      <div class="profit">
                         <div class="label">{{$t('new.doc29_1')}}:</div>
                         <div class="value">${{item.profit}}</div>
                      </div>
                   </div>
                </div>
               <div class="rank-box">
                 No.{{item.rank}}
               </div>
             </div>
          </van-cell>
        </van-list>
        <div class="show-null" v-if="showNull">
          <img src="../../assets/images/fianacial_no_data.png" alt="" />
          <p>{{$t('new.desc104')}}</p>
        </div>
      </div>
    </div>



  </div>
</template>

<script>
export default {
  name: "rank",
  data(){
    return {
      titleSize: this.$t('new.doc26'),
      is_mt: true,
      list: [],
      page:1,
      showNull:false,
      finished: false,
      loading: false,
      rank3Data:{
        item1: {},
        item2:{},
        item3:{}
      }
    }
  },
  created() {

  },
  methods:{
    onLoad() {
      setTimeout(() => {
        this.$post(this.URL.user.userRank, {
          page: this.page,
          pageSize:10
        }).then(res => {
          console.log("====res",res)
          if (res.code == 0) {
            if (this.page == 1) {
               this.list = res.data.list
            } else {
              this.list = this.list.concat(res.data.list)
            }

            if(this.list.length>1){
              this.rank3Data.item1=this.list[1]||{}
              this.rank3Data.item2=this.list[2]||{}
              this.rank3Data.item3=this.list[3]||{}
            }else {
              this.rank3Data.item1=this.list[0]||{}
              this.rank3Data.item2={}
              this.rank3Data.item3={}
            }






            if(this.list.length==0){
              this.showNull=true;
            }
            if (res.data.list.length > 9) {
              this.page++;
            }
            this.loading = false;
            if (this.list.length >= parseFloat(res.data.page.count)) {
              this.finished = true;
            }
          } else {
            this.$toast(res.message)
          }
        })
      }, 500);
    },
  }
}
</script>

<style lang="less" scoped>
.rank-container{
  background:#F7F9FC;
  height:100%;
  .business-top {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 1.04rem;
    background: #fff;
    z-index: 6;
    text-align: center;
    line-height: 1.04rem;
    display: flex;
    align-items: center;

    .right-box, .left-box {
      width: 1.02rem;
      height: .64rem;
      display: flex;
      align-items: center;
      flex-shrink: 0;

    }

    .back {
      width: 1.02rem;
      height: .64rem;
      margin-left: 10px;
    }

    .title {
      flex: 1;
      font-size: .4rem;
      color: rgba(50, 50, 50, 1);
      align-items: center;
    }

    .right-box {
      .record {
        width: .48rem;
        height: .48rem;
        top: -0.08rem;
        position: relative;
        align-self: flex-end;
      }

      display: flex;
      justify-content: flex-end;
      padding-right: 10px;
    }

  }
  .container{
    padding: .98rem 0;
  }
  .rank-top-box{
     margin:20px 20px;
     height: 180px;
     background: url("~@/assets/images/rank-bg.png") no-repeat;
     background-size: 100% 100%;
     display:flex;
    color: #1E1E1E;
    .box1{
       flex:1;
       flex-direction: column;
       justify-content: flex-end;
       align-items: center;
       display: flex;
      padding-bottom:35px;

    }
    .box2{
      flex:1.1;
      padding-bottom:55px;
      flex-direction: column;
      justify-content: flex-end;
      align-items: center;
      display: flex;

    }
    .box3{
      flex:1;
      padding-bottom:35px;
      flex-direction: column;
      justify-content: flex-end;
      align-items: center;
      display: flex;
    }
    .img-bg{
      width:100px;
      height:77px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      .rank{
        width: 100%;
        height: 100%;
        position: absolute;
        z-index: 2;
      }
    }
    .img1,.img2,.img3{
      .head {
        width: 50px;
        height: 50px;
        position: relative;
        z-index: 1;
        top:3px
      }

    }
  }
  .record-con{
    margin:10px;
    .van-cell{
      margin-bottom: 10px;
      border-radius: 10px;
    }
  }
  .item-box{
    display: flex;
    margin-bottom: 10px;
    .info{
      flex:1;
      display:flex;
      align-items: center;
      flex-direction: row;
      .head{
        width: 40px;
        height: 40px;
      }

    }
    .profit-box{
      display:flex;
      flex: 1;
      flex-direction: column;
      margin-left: 10px;
      .name{
        font-size: 18px;
        color: rgba(30, 30, 30, 1);
      }
      .profit{

        display: flex;
        align-items: center;
        font-size: 12px;
        color: rgba(175, 171, 171, 1);
      }
    }
    .rank-box{
      min-width: 50px;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 18px;
      font-weight: 500;
      color: rgba(113, 63, 245, 1);
    }
  }
}

</style>
